import {request} from "@umijs/max";
import {ADMIN_API} from "@/services/admin/typings";

/**
 * 使用账号密码登录
 * @param dto
 */
export const login = async (dto: ADMIN_API.LoginDTO) => {
  return request<ADMIN_API.LoginVO>('/api/auth/login', {
    method: 'POST',
    data: dto
  })
}

export const logout = async () => {
  return request('/api/auth/logout', {
    method: 'POST'
  })
}

/**
 * 获取用户信息
 */
export const fetchUserInfo = async () => {
  return request<ADMIN_API.UserInfoVO>('/api/user/userInfo', {method: 'GET'})
}

export interface UserUpdateDTO {
  id?: string;
  name: string;
  password?: string;
}

export const saveUser = async (data: UserUpdateDTO) => {
  return request<ADMIN_API.UserInfoVO>(`/api/user/save`, {method: 'POST', data})
}

export const updateUser = async (data: UserUpdateDTO) => {
  return request<ADMIN_API.UserInfoVO>(`/api/user/update`, {method: 'POST', data})
}
